﻿using System;
using System.Linq;
using System.Text;
using System.DirectoryServices;
using System.Collections.Generic;

namespace Cratos.Tools.Security
{
	/// <summary>
	/// Cratos Active Directory Helper clas
	/// </summary>
	public static class CratosADHelper
	{
		#region Class Constant declarations
		#endregion

		#region Class Event declarations
		#endregion

		#region Class Variable declarations
		#endregion

		#region Class Constructors & Destructors
		#endregion

		#region Class Properties
		#endregion

		#region Class Methods
		/// <summary>
		/// Authenticate the User against AD
		/// </summary>
		/// <param name="userName">User Name</param>
		/// <param name="userPassword">User Password</param>
		/// <param name="userDomain">User Domain</param>
		/// <returns>A boolean indicating the success of the method</returns>
		public static bool Authenticate(string userName, string userPassword, string userDomain)
		{
			// Declare the required variables
			bool						returnValue = false;
			object					nativeObject;
			DirectoryEntry	dirEntry;

			try
			{
				// Create and Setup a new Directory entry and a Native Object
				dirEntry     = new DirectoryEntry("LDAP://" + userDomain, userName, userPassword);
				nativeObject = dirEntry.NativeObject;

				// Set the successful return value
				returnValue = true;
			}
			catch (DirectoryServicesCOMException) { }

			// Return to calling method
			return (returnValue);
		}
		#endregion

		#region Class Support Methods
		#endregion
	}
}
